package br.com.android.financas.adapter;

import java.text.NumberFormat;
import java.util.List;

import org.joda.time.DateTime;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import br.com.android.financas.R;
import br.com.android.financas.model.Recorrente;

public class RecorrenteListaAdapter extends ArrayAdapter<Recorrente> {

	private Activity activity;

	public RecorrenteListaAdapter(Context context, int textViewResourceId, List<Recorrente> items) {
		super(context, textViewResourceId, items);
		this.activity=(Activity) context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {

			LayoutInflater vi =activity.getLayoutInflater(); //getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.recorrente_item, null);
		}
		Recorrente recorrente = getItem(position);

		TextView descricao = (TextView) v
				.findViewById(R.recorrenteLista.titulo);
		TextView dia = (TextView) v
				.findViewById(R.recorrenteLista.dia);
		TextView valor = (TextView) v
				.findViewById(R.recorrenteLista.valor);
		TextView categoria = (TextView) v
				.findViewById(R.recorrenteLista.categoria);

		descricao.setText(recorrente.getDescricao());
		dia.setText((new DateTime(recorrente.getData().getTime())).toString("dd"));
		valor.setText(NumberFormat.getCurrencyInstance().format(
				recorrente.getValor()));
		categoria.setBackgroundColor(recorrente.getCor());
		return v;
	}

}